import apiClient from '@/api/apiClient';
import { SubDictionariesData } from '@/pages/setting/dictionary/sub-data/type';

import { ListData } from '#/entity';

const list = (dictId: string, data) => {
  data.typeId = dictId;
  return apiClient.get<ListData<SubDictionariesData>>({ url: `/dict-data`, params: data });
};

const listByKey = (dictKey: string, data) => {
  data.typeKey = dictKey;
  return apiClient.get({ url: `/dict-data/list`, params: data });
};

const get = (id: string) => {
  return apiClient.get<SubDictionariesData>({ url: `/dict-data/${id}` });
};

const edit = (id: string, data: SubDictionariesData) =>
  apiClient.put({
    url: `/dict-data/${id}`,
    data,
  });

const remove = (data: { ids: string[] }) => apiClient.delete<number>({ url: `/dict-data`, data });

const add = (data: SubDictionariesData) =>
  apiClient.post({
    url: `/dict-data`,
    data,
  });

export default {
  list,
  edit,
  add,
  get,
  remove,
  listByKey,
};
